const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const ManiFestPlugin = require('webpack-manifest-plugin');
module.exports = {
    entry: {
       app: "./src/index.js",
       vendors: "./src/vendors.js"
    },
    output: {
        filename: "[name]/bundle.js",
        path: path.resolve(__dirname, "dist"),
        // publicPath: "http://cdn.example.com/assets/[hash]/" // 会拼接在最终html资源引入的最前面， 一般上为 / 或者 空， 如果有cdn 则是cdn地址
    },
    mode: "development",
    plugins: [
        new HtmlWebpackPlugin({
            template: "src/index.html",
        }),
        new CleanWebpackPlugin(),
        new ManiFestPlugin()
    ],
    devServer: {
        contentBase: "./dist",
        port: "8080",
        host: "localhost",
        open: true
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                use: {
                    loader: 'webpack-jdists-loader',
                    options: {
                        trigger: 'prod'
                    }
                }
            },
            {
                test: /\.(css|scss)/,
                use: ['style-loader', 'css-loader'],
                exclude: /node_modules/,
                include: path.resolve(__dirname, 'src')
            },
            {
                test: /\.(png|jpg|gif)$/i,
                use: [
                    {
                        loader: 'url-loader',
                        options: {
                            limit: 8192,
                            outputPath: 'images'
                        }
                    }
                ]
            },
            {
                test: /\.txt$/,
                use: {
                    loader: path.resolve(__dirname,'loader/index.js'),
                    options: {
                        name: '李晋飞'
                    }
                }
            },
            {
                test: /\.csv$/,
                use: {
                    loader: 'csv-loader'
                }
            },
            {
                test: /\.xml$/,
                use: {
                    loader: 'xml-loader'
                }
            }
        ]
    }
};